// 用户认证相关工具函数

interface UserInfo {
    userId: string;
    username: string;
    studentId: string;
    schoolName: string;
    schoolId: string;
    avatarImage: string;
    isAvatarImageSet: boolean;
}

// 保存用户信息到本地存储
export const saveUserInfo = (userInfo: UserInfo): void => {
    localStorage.setItem('userInfo', JSON.stringify(userInfo));
};

// 获取用户信息
export const getUserInfo = (): UserInfo | null => {
    const userInfo = localStorage.getItem('userInfo');
    return userInfo ? JSON.parse(userInfo) : null;
};

// 清除用户信息
export const clearUserInfo = (): void => {
    localStorage.removeItem('userInfo');
};

// 检查用户是否已登录
export const isLoggedIn = (): boolean => {
    return getUserInfo() !== null;
};

// 获取用户ID
export const getUserId = (): string | null => {
    const userInfo = getUserInfo();
    return userInfo ? userInfo.userId : null;
};

// 获取用户名
export const getUsername = (): string | null => {
    const userInfo = getUserInfo();
    return userInfo ? userInfo.username : null;
};

// 获取学号
export const getStudentId = (): string | null => {
    const userInfo = getUserInfo();
    return userInfo ? userInfo.studentId : null;
};

// 获取学校ID
export const getSchoolId = (): string | null => {
    const userInfo = getUserInfo();
    return userInfo ? userInfo.schoolId : null;
};